import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:yi_shop/components/search/brand.dart';
import 'package:yi_shop/components/search/goods.dart';
import 'package:yi_shop/components/search/store.dart';
import 'package:yi_shop/components/search/user.dart';
import 'package:yi_shop/ui/keep_alive.dart';
import 'package:yi_shop/utils/colors.dart';
import 'package:yi_shop/utils/styles.dart';
import 'package:yi_shop/utils/svg.dart';
import 'package:yi_shop/utils/tools.dart';

class SearchResultController extends GetxController with GetSingleTickerProviderStateMixin {
  List<String> tabs = ['商品', '品牌', '用户', '店铺'];

  late TabController controller;

  @override
  void onInit() {
    controller = TabController(length: tabs.length, vsync: this);
    super.onInit();
  }

  @override
  void onClose() {
    controller.dispose();
    super.onClose();
  }
}

class SearchResultPage extends GetView<SearchResultController> {
  const SearchResultPage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        leading: ToolsUtils.builderLeading(),
        title: TextField(
          decoration: InputDecoration(
            hintText: '',
            hintStyle: StylesUtils.customTextStyle(
                color: ColorsUtils.color9999, fontSize: StylesUtils.fontSize13),
            border: OutlineInputBorder(
                borderRadius: BorderRadius.circular(20), borderSide: BorderSide.none),
            focusedBorder: OutlineInputBorder(
                borderRadius: BorderRadius.circular(20), borderSide: BorderSide.none),
            isCollapsed: false,
            isDense: false,
            prefixIconConstraints: const BoxConstraints.expand(width: 40, height: 15),
            prefixIcon: Padding(
              padding: const EdgeInsets.only(left: 5),
              child: SvgUtils.assetName('shape_u373', width: 14.w, height: 14.h),
            ),
            contentPadding: const EdgeInsets.symmetric(vertical: 10, horizontal: 15),
            constraints: const BoxConstraints.expand(height: 35),
            filled: true,
            fillColor: ColorsUtils.parseColorFromHexString(ColorsUtils.colorF5f5),
          ),
          style: StylesUtils.customTextStyle(
            color: ColorsUtils.color3333,
          ),
          onChanged: (String search) {},
          onSubmitted: (String search) {},
        ),
        actions: [
          TextButton(
              onPressed: () {},
              child: Text(
                '取消',
                style: StylesUtils.customTextStyle(),
              ))
        ],
        bottom: PreferredSize(
          preferredSize: const Size.fromHeight(40),
          child: Container(
            height: 40,
            color: Colors.white,
            child: ToolsUtils.getClientTabBar(
              controller.tabs,
              controller.controller,
              isScrollable: false,
            ),
          ),
        ),
      ),
      body: TabBarView(
        controller: controller.controller,
        children: [
          KeepAliveWrapperTabView(
              child: const SearchGoodsView(),
              callback: () {
                Get.put(SearchGoodsController());
              }),
          KeepAliveWrapperTabView(
              child: const SearchBrandView(),
              callback: () {
                Get.put(SearchBrandController());
              }),
          KeepAliveWrapperTabView(
              child: const SearchUserView(),
              callback: () {
                Get.put(SearchUserController());
              }),
          KeepAliveWrapperTabView(
              child: const SearchStoreView(),
              callback: () {
                Get.put(SearchStoreController());
              }),
        ],
      ),
    );
  }
}
